package com.demo.controller;

import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.demo.bean.WdApartmentLayout;
import com.demo.bean.WdChangeType;
import com.demo.service.HouseTypeService;

@Controller
public class HouseTypeController {

	@Autowired
	private HouseTypeService service;

	/*	
	*//**
	 * 自动生成32位的UUid，对应数据库的主键id进行插入用。
	 * 
	 * @return
	 */
	/*
	 * public static String getUUID() { UUID uuid = UUID.randomUUID(); String
	 * str = uuid.toString(); // 去掉"-"符号 String temp = str.substring(0, 8) +
	 * str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) +
	 * str.substring(24); return temp;
	 * 
	 * return UUID.randomUUID().toString().replace("-", ""); } public static
	 * void main(String[] args) {
	 * 
	 * System.out.println( getUUID());
	 * 
	 * }
	 */

	@RequestMapping("/houseType.do")
	public String getList(HttpServletRequest requset,WdApartmentLayout bean) {
		List<HouseTypeService> list = service.getList(bean);
		requset.setAttribute("list", list);
		return "houseType";
	}

	@RequestMapping("/houseType_to_add.do")
	public String houseTypeToAdd() {
		return "houseType_add";
	}

	@RequestMapping("/houseType_add.do")
	public String houseTypeAdd(WdApartmentLayout bean) {
		bean.setApartmentLayoutId(UUID.randomUUID().toString().replace("-", ""));
		service.insertSelective(bean);
		return "redirect:houseType.do";
	}

	@RequestMapping("/deletApartmentLayout.do")
	public String houseTypeDelete(String apartmentLayoutId) {
		service.deleteSelective(apartmentLayoutId);
		return "redirect:houseType.do";
	}

	@RequestMapping("/toupdateApartmentLayout.do")
	public String houseTypeToUpdate(HttpServletRequest requset,
			String apartmentLayoutId) {
		WdApartmentLayout bean = service.getById(apartmentLayoutId);
		requset.setAttribute("bean", bean);
		return "houseType_update";
	}

	@RequestMapping("/updateApartmentLayout.do")
	public String houseTypeUpdate(WdApartmentLayout bean) {
		service.updateApartmentLayout(bean);
		return "redirect:houseType.do";
	}

	
}
